package Controller

import (
	"github.com/gin-gonic/gin"
	"selfService/ginWeb/Service"
	"selfService/tool"
)
var FriendService Service.FrineService

//     rpc get_friends(get_friends_request) returns (get_friends_response);
////   根据id获得好友id列表
func Get_friends(c *gin.Context)  {
	userid := c.Query("userid")
	user, err := FriendService.Get_friends(userid)
	if err != nil{
		tool.Failed(c,"失败")
		return
	}else {
		tool.Success(c,user)
	}
}

//     rpc get_apply(get_apply_request) returns (get_apply_response);          // 根据id获得申请人id列表
//// 根据id获得申请人id列表
func Get_apply(c *gin.Context)  {
	userid := c.Query("userid")
	user, err := FriendService.Get_apply(userid)
	if err != nil{
		tool.Failed(c,"失败")
		return
	}else {
		tool.Success(c,user)
	}
}

//    rpc agree_apply(agree_apply_request) returns (agree_apply_response);    // 根据id同意申请     // 根据id获得申请人id列表
//    根据id同意申请
func Agree_apply(c *gin.Context)  {
	userid := c.Query("hostId")
	userid2 := c.Query("applyId")
	user, err := FriendService.Agree_apply(userid,userid2)
	if err != nil{
		tool.Failed(c,err.Error())
		return
	}else {
		tool.Success(c,user)
	}
}


//     rpc refuse_apply(refuse_apply_request) returns (refuse_apply_response); // 根据id拒绝申请
//   // 根据id拒绝申请
func Refuse_apply(c *gin.Context)  {
	userid := c.Query("hostId")
	userid2 := c.Query("applyId")
	user, err := FriendService.Refuse_apply(userid,userid2)
	if err != nil{
		tool.Failed(c,"失败")
		return
	}else {
		tool.Success(c,user)
	}
}


//     rpc create_apply(create_apply_request) returns (create_apply_response); // 传⼊id1和2进⾏好友添加
//      // 传⼊id1和2进⾏好友添加
func Create_apply(c *gin.Context)  {
	userid := c.Query("hostId")
	userid2 := c.Query("applyId")
	user, err := FriendService.Create_apply(userid,userid2)
	if err != nil{
		tool.Failed(c,"失败")
		return
	}else {
		tool.Success(c,user)
	}
}


//      rpc delete_friend(deleteFriend_requese) returns(deleteFriend_response); // 传入id 删除两个好友关系
//     / 传入id 删除两个好友关系
func Delete_friend(c *gin.Context)  {
	hostId := c.Query("hostId")
	friendId := c.Query("friendId")
	user, err := FriendService.Delete_friend(hostId, friendId)
	if err != nil{
		tool.Failed(c,"失败")
		return
	}
	if user.State == "500"{
		tool.Failed(c,user.Message)
		return
	} else {
		tool.Success(c,user)
	}
}
